package com.itheima.controller;


import com.itheima.pojo.Result;
import com.itheima.utils.AliyunOSSOperator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
public class UploadController {
    //注入阿里云util 工具类对象
    @Autowired
    private AliyunOSSOperator aliyunOSSOperator;
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
        log.info("文件上传开始");
        //1.接收请求参数：MultipartFile

        //2.使用工具类,实现文件上传到阿里云服务器中
        String fileUrl = aliyunOSSOperator.upload(file.getBytes(), file.getOriginalFilename());

        //3.返回响应结果（文件上传的url地址）
        return Result.success(fileUrl);
    }


}
